{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 金融期权T型报价\n",
    "金融期权T型报价的接口为\n",
    "\n",
    "`optshare.get_financial_option_quotes(exchange_name, calendar=optshare.Calendar(), display=True)`\n",
    "\n",
    "其中，\n",
    "\n",
    "- **exchange_name**: 指定交易所名称，支持上交所(`'sse'`)、深交所(`'szse'`)，以及中金所(`'cffex'`)的金融期权T型报价\n",
    "- **calendar**: 指定交易日历，默认值为`optshare.Calendar()`，默认使用[在线节假日信息](https://gitee.com/luluUCD/optshare/raw/master/src/optshare/dateutils/China.txt)，也可以通过指定带有节假日列表的txt文件来指定交易日历，更多信息详见[日历接口](https://optshare.readthedocs.io/en/latest/api_references/optshare.dateutils.html#calendar-definition)。\n",
    "- **display**: 在获取T型报价时，是否展示期权报价的种类，默认值为True。"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## ETF期权\n",
    "### 上交所ETF期权T型报价"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fetch option quotes for  510050\n",
      "fetch option quotes for  510300\n",
      "fetch option quotes for  510500\n"
     ]
    },
    {
     "data": {
      "text/plain": "                   日期   行权价  看涨合约-最新价  看跌合约-最新价  挂钩标的代码  挂钩标的-最新价        到期日期\n0    2023-02-16 11:21  2.45    0.3439    0.0001  510050     2.791  2023-02-22\n1    2023-02-16 11:21  2.50    0.2935    0.0001  510050     2.791  2023-02-22\n2    2023-02-16 11:21  2.55    0.2430    0.0001  510050     2.791  2023-02-22\n3    2023-02-16 11:21  2.60    0.1944    0.0004  510050     2.791  2023-02-22\n4    2023-02-16 11:21  2.65    0.1440    0.0007  510050     2.791  2023-02-22\n..                ...   ...       ...       ...     ...       ...         ...\n207  2023-02-16 11:21  6.50    0.3002    0.3705  510500     6.441  2023-09-27\n208  2023-02-16 11:21  6.75    0.2054    0.5250  510500     6.441  2023-09-27\n209  2023-02-16 11:21  7.00    0.1302       NaN  510500     6.441  2023-09-27\n210  2023-02-16 11:21  7.25    0.0910       NaN  510500     6.441  2023-09-27\n211  2023-02-16 11:21  7.50    0.0596       NaN  510500     6.441  2023-09-27\n\n[212 rows x 7 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>行权价</th>\n      <th>看涨合约-最新价</th>\n      <th>看跌合约-最新价</th>\n      <th>挂钩标的代码</th>\n      <th>挂钩标的-最新价</th>\n      <th>到期日期</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.45</td>\n      <td>0.3439</td>\n      <td>0.0001</td>\n      <td>510050</td>\n      <td>2.791</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.50</td>\n      <td>0.2935</td>\n      <td>0.0001</td>\n      <td>510050</td>\n      <td>2.791</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.55</td>\n      <td>0.2430</td>\n      <td>0.0001</td>\n      <td>510050</td>\n      <td>2.791</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.60</td>\n      <td>0.1944</td>\n      <td>0.0004</td>\n      <td>510050</td>\n      <td>2.791</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.65</td>\n      <td>0.1440</td>\n      <td>0.0007</td>\n      <td>510050</td>\n      <td>2.791</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>207</th>\n      <td>2023-02-16 11:21</td>\n      <td>6.50</td>\n      <td>0.3002</td>\n      <td>0.3705</td>\n      <td>510500</td>\n      <td>6.441</td>\n      <td>2023-09-27</td>\n    </tr>\n    <tr>\n      <th>208</th>\n      <td>2023-02-16 11:21</td>\n      <td>6.75</td>\n      <td>0.2054</td>\n      <td>0.5250</td>\n      <td>510500</td>\n      <td>6.441</td>\n      <td>2023-09-27</td>\n    </tr>\n    <tr>\n      <th>209</th>\n      <td>2023-02-16 11:21</td>\n      <td>7.00</td>\n      <td>0.1302</td>\n      <td>NaN</td>\n      <td>510500</td>\n      <td>6.441</td>\n      <td>2023-09-27</td>\n    </tr>\n    <tr>\n      <th>210</th>\n      <td>2023-02-16 11:21</td>\n      <td>7.25</td>\n      <td>0.0910</td>\n      <td>NaN</td>\n      <td>510500</td>\n      <td>6.441</td>\n      <td>2023-09-27</td>\n    </tr>\n    <tr>\n      <th>211</th>\n      <td>2023-02-16 11:21</td>\n      <td>7.50</td>\n      <td>0.0596</td>\n      <td>NaN</td>\n      <td>510500</td>\n      <td>6.441</td>\n      <td>2023-09-27</td>\n    </tr>\n  </tbody>\n</table>\n<p>212 rows × 7 columns</p>\n</div>"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import optshare\n",
    "optshare.get_financial_option_quotes(exchange_name = 'sse')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 深交所ETF期权T型报价"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fetch option quotes for  159919\n",
      "fetch option quotes for  159922\n",
      "fetch option quotes for  159915\n"
     ]
    },
    {
     "data": {
      "text/plain": "                   日期   行权价  看涨合约-最新价  看跌合约-最新价  挂钩标的代码  挂钩标的-最新价        到期日期\n0    2023-02-16 11:21  3.50       NaN    0.0001  159919     4.236  2023-02-22\n1    2023-02-16 11:21  3.60    0.6287    0.0001  159919     4.236  2023-02-22\n2    2023-02-16 11:21  3.70    0.5307    0.0001  159919     4.236  2023-02-22\n3    2023-02-16 11:21  3.80    0.4326    0.0001  159919     4.236  2023-02-22\n4    2023-02-16 11:21  3.90    0.3340    0.0004  159919     4.236  2023-02-22\n..                ...   ...       ...       ...     ...       ...         ...\n153  2023-02-16 11:21  2.55    0.1469    0.1929  159915     2.485  2023-09-27\n154  2023-02-16 11:21  2.60    0.1263    0.2219  159915     2.485  2023-09-27\n155  2023-02-16 11:21  2.65    0.1054    0.2570  159915     2.485  2023-09-27\n156  2023-02-16 11:21  2.70    0.0925    0.2992  159915     2.485  2023-09-27\n157  2023-02-16 11:21  2.75    0.0800    0.3308  159915     2.485  2023-09-27\n\n[158 rows x 7 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>行权价</th>\n      <th>看涨合约-最新价</th>\n      <th>看跌合约-最新价</th>\n      <th>挂钩标的代码</th>\n      <th>挂钩标的-最新价</th>\n      <th>到期日期</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2023-02-16 11:21</td>\n      <td>3.50</td>\n      <td>NaN</td>\n      <td>0.0001</td>\n      <td>159919</td>\n      <td>4.236</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2023-02-16 11:21</td>\n      <td>3.60</td>\n      <td>0.6287</td>\n      <td>0.0001</td>\n      <td>159919</td>\n      <td>4.236</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2023-02-16 11:21</td>\n      <td>3.70</td>\n      <td>0.5307</td>\n      <td>0.0001</td>\n      <td>159919</td>\n      <td>4.236</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2023-02-16 11:21</td>\n      <td>3.80</td>\n      <td>0.4326</td>\n      <td>0.0001</td>\n      <td>159919</td>\n      <td>4.236</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2023-02-16 11:21</td>\n      <td>3.90</td>\n      <td>0.3340</td>\n      <td>0.0004</td>\n      <td>159919</td>\n      <td>4.236</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>153</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.55</td>\n      <td>0.1469</td>\n      <td>0.1929</td>\n      <td>159915</td>\n      <td>2.485</td>\n      <td>2023-09-27</td>\n    </tr>\n    <tr>\n      <th>154</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.60</td>\n      <td>0.1263</td>\n      <td>0.2219</td>\n      <td>159915</td>\n      <td>2.485</td>\n      <td>2023-09-27</td>\n    </tr>\n    <tr>\n      <th>155</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.65</td>\n      <td>0.1054</td>\n      <td>0.2570</td>\n      <td>159915</td>\n      <td>2.485</td>\n      <td>2023-09-27</td>\n    </tr>\n    <tr>\n      <th>156</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.70</td>\n      <td>0.0925</td>\n      <td>0.2992</td>\n      <td>159915</td>\n      <td>2.485</td>\n      <td>2023-09-27</td>\n    </tr>\n    <tr>\n      <th>157</th>\n      <td>2023-02-16 11:21</td>\n      <td>2.75</td>\n      <td>0.0800</td>\n      <td>0.3308</td>\n      <td>159915</td>\n      <td>2.485</td>\n      <td>2023-09-27</td>\n    </tr>\n  </tbody>\n</table>\n<p>158 rows × 7 columns</p>\n</div>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_financial_option_quotes(exchange_name = 'szse')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 股指期权"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fetch option quotes for  000300\n",
      "fetch option quotes for  000852\n",
      "fetch option quotes for  000016\n"
     ]
    },
    {
     "data": {
      "text/plain": "                   日期     行权价  看涨合约-最新价  看跌合约-最新价  挂钩标的代码  挂钩标的-最新价  \\\n0    2023-02-16 11:21  3400.0     765.4       NaN  IO2312   4163.91   \n1    2023-02-16 11:21  3500.0     685.0       NaN  IO2312   4163.91   \n2    2023-02-16 11:21  3600.0     573.0      67.4  IO2312   4163.91   \n3    2023-02-16 11:21  3700.0     529.6      86.2  IO2312   4163.91   \n4    2023-02-16 11:21  3800.0     456.2     112.4  IO2312   4163.91   \n..                ...     ...       ...       ...     ...       ...   \n335  2023-02-16 11:21  2800.0       NaN       NaN  HO2309   2782.14   \n336  2023-02-16 11:21  2900.0      99.0       NaN  HO2309   2782.14   \n337  2023-02-16 11:21  3000.0      70.4       NaN  HO2309   2782.14   \n338  2023-02-16 11:21  3100.0       NaN       NaN  HO2309   2782.14   \n339  2023-02-16 11:21  3200.0       NaN       NaN  HO2309   2782.14   \n\n           到期日期  \n0    2023-12-15  \n1    2023-12-15  \n2    2023-12-15  \n3    2023-12-15  \n4    2023-12-15  \n..          ...  \n335  2023-09-15  \n336  2023-09-15  \n337  2023-09-15  \n338  2023-09-15  \n339  2023-09-15  \n\n[340 rows x 7 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>行权价</th>\n      <th>看涨合约-最新价</th>\n      <th>看跌合约-最新价</th>\n      <th>挂钩标的代码</th>\n      <th>挂钩标的-最新价</th>\n      <th>到期日期</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2023-02-16 11:21</td>\n      <td>3400.0</td>\n      <td>765.4</td>\n      <td>NaN</td>\n      <td>IO2312</td>\n      <td>4163.91</td>\n      <td>2023-12-15</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2023-02-16 11:21</td>\n      <td>3500.0</td>\n      <td>685.0</td>\n      <td>NaN</td>\n      <td>IO2312</td>\n      <td>4163.91</td>\n      <td>2023-12-15</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2023-02-16 11:21</td>\n      <td>3600.0</td>\n      <td>573.0</td>\n      <td>67.4</td>\n      <td>IO2312</td>\n      <td>4163.91</td>\n      <td>2023-12-15</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2023-02-16 11:21</td>\n      <td>3700.0</td>\n      <td>529.6</td>\n      <td>86.2</td>\n      <td>IO2312</td>\n      <td>4163.91</td>\n      <td>2023-12-15</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2023-02-16 11:21</td>\n      <td>3800.0</td>\n      <td>456.2</td>\n      <td>112.4</td>\n      <td>IO2312</td>\n      <td>4163.91</td>\n      <td>2023-12-15</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>335</th>\n      <td>2023-02-16 11:21</td>\n      <td>2800.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>HO2309</td>\n      <td>2782.14</td>\n      <td>2023-09-15</td>\n    </tr>\n    <tr>\n      <th>336</th>\n      <td>2023-02-16 11:21</td>\n      <td>2900.0</td>\n      <td>99.0</td>\n      <td>NaN</td>\n      <td>HO2309</td>\n      <td>2782.14</td>\n      <td>2023-09-15</td>\n    </tr>\n    <tr>\n      <th>337</th>\n      <td>2023-02-16 11:21</td>\n      <td>3000.0</td>\n      <td>70.4</td>\n      <td>NaN</td>\n      <td>HO2309</td>\n      <td>2782.14</td>\n      <td>2023-09-15</td>\n    </tr>\n    <tr>\n      <th>338</th>\n      <td>2023-02-16 11:21</td>\n      <td>3100.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>HO2309</td>\n      <td>2782.14</td>\n      <td>2023-09-15</td>\n    </tr>\n    <tr>\n      <th>339</th>\n      <td>2023-02-16 11:21</td>\n      <td>3200.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>HO2309</td>\n      <td>2782.14</td>\n      <td>2023-09-15</td>\n    </tr>\n  </tbody>\n</table>\n<p>340 rows × 7 columns</p>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_financial_option_quotes(exchange_name = 'cffex')"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
